package com.tjsoft.system.service;

import java.io.File;

import jxl.Sheet;
import jxl.Workbook;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tjsoft.system.dao.CompDAO;
import com.tjsoft.system.entity.base.Comp;

@Service
public class ImportManager {
	
	@Autowired
	private CompDAO compDAO;


	
	private Workbook book = null;
	
	@Transactional
	public void importInitData(String path) throws Exception {
		book = Workbook.getWorkbook(new File(path+"init\\init.xls"));
		importComp();

	}
	

	
	/**
	 * 导入职务信息
	 * @throws Exception
	 */
	private void importComp() throws Exception{
		Sheet sheet = book.getSheet("init");
		int rowCount = sheet.getRows();
		
		for(int i=1;i<rowCount;i++){//第一行是标题，从第二行开始

			String  name = sheet.getCell(1,i).getContents();
			String  gender = sheet.getCell(2,i).getContents();
			String  age = sheet.getCell(3,i).getContents().trim();
			String  degree = sheet.getCell(4,i).getContents();
			String  idCard = sheet.getCell(5,i).getContents();
			String  personType = sheet.getCell(6,i).getContents();
			String  industry = sheet.getCell(7,i).getContents();
			String  compName = sheet.getCell(8,i).getContents();
			String  address = sheet.getCell(9,i).getContents();
			String  empCount = sheet.getCell(10,i).getContents().trim();
			String  isGeti = sheet.getCell(11,i).getContents();
			String  zhuceMoney = sheet.getCell(12,i).getContents();
			String  touzhiMoney = sheet.getCell(13,i).getContents();
			String  compType = sheet.getCell(14,i).getContents();
			String  industryType = sheet.getCell(15,i).getContents();
			String  bankAddress = sheet.getCell(16,i).getContents();
			String  bankNo = sheet.getCell(17,i).getContents();
			String  selfTouzhiMoney = sheet.getCell(18,i).getContents();
			String  govBuzhuMoney = sheet.getCell(19,i).getContents();
			String  phone = sheet.getCell(20,i).getContents();
			String  town = sheet.getCell(21,i).getContents();
			String  peixun = sheet.getCell(22,i).getContents();
			String  gss = sheet.getCell(23,i).getContents();
//			String  chengliDate = sheet.getCell(24,i).getContents();
//			String  note = sheet.getCell(25,i).getContents();
			
			Comp c = new Comp();
			c.setName(name);
			c.setGender(gender);
			if(!"".equals(age)){
				c.setAge(Integer.parseInt(age));
			}
			c.setDegree(degree);
			c.setIdCard(idCard);
			c.setPersonType(personType);
			c.setIndustry(industry);
			c.setCompName(compName);
			c.setAddress(address);
			if(!"".equals(empCount)){
				c.setEmpCount(Integer.parseInt(empCount));
			}
			c.setIsGeti(isGeti);
			if(!"".equals(zhuceMoney)){
				c.setZhuceMoney(Double.parseDouble(zhuceMoney));
			}
			if(!"".equals(touzhiMoney)){
				c.setTouzhiMoney(Double.parseDouble(touzhiMoney));
			}
			c.setCompType(compType);
			c.setIndustryType(industryType);
			c.setBankAddress(bankAddress);
			c.setBankNo(bankNo);
			if(!"".equals(selfTouzhiMoney)){
				c.setSelfTouzhiMoney(Double.parseDouble(selfTouzhiMoney));
			}
			if(!"".equals(govBuzhuMoney)){
				c.setGovBuzhuMoney(Double.parseDouble(govBuzhuMoney));
			}
			c.setPhone(phone);
			c.setTown(town);
			c.setPeixun(peixun);
			c.setGss(gss);
//			if(!"".equals(chengliDate)){
//				SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd");
//				c.setChengliDate(sdf.parse(chengliDate));
//			}
			
			compDAO.save(c);
		}
	}



	public CompDAO getCompDAO() {
		return compDAO;
	}



	public void setCompDAO(CompDAO compDAO) {
		this.compDAO = compDAO;
	}
	
	

}
